package com.cuitrip.business.user;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.cuitrip.business.login.LoginInstance;
import com.cuitrip.service.R;
import com.cuitrip.util.track.TrackUtil;
import com.lab.app.customui.CustomUiConfig;
import com.lab.app.customui.CustomUiFragmentActivity;
import com.lab.jumper.Jumper;


/**
 * Created on 7/16.
 * “关于我”的界面
 */
public class PersonActivity extends CustomUiFragmentActivity {

    private PersonalFragment personalFragment;
    private static final int REQUEST_CODE_EDIT_SELF_INFO = 21;
    public static final String USER_ID_KEY = "user_id";
    public static final String USER_NAME_KEY = "user_name";
    private String uid;
    private String name;

    public static void jumpPersonActivity(Context context, String name, String uid){
        Intent intent = new Intent(context, PersonActivity.class);
        intent.putExtra(USER_ID_KEY, uid);
        intent.putExtra(USER_NAME_KEY, name);
        Jumper.launchActivity(context, intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (getIntent().hasExtra(USER_ID_KEY)) {
            uid = getIntent().getStringExtra(USER_ID_KEY);
        } else {
            finish();
        }
        if (getIntent().hasExtra(USER_NAME_KEY)) {
            name = getIntent().getStringExtra(USER_NAME_KEY);
        }
        super.onCreate(savedInstanceState,R.layout.page_container_layout);
    }

    public void initView() {
        personalFragment = new PersonalFragment();
        personalFragment.setUid(uid);
        openFragment(personalFragment, R.id.container, PersonalFragment.class.getName());
    }


    @Override
    public void onTopbarLeftPress() {
        finish();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_EDIT_SELF_INFO) {
            personalFragment.refreshUserInfo();
        }
    }

    @Override
    public boolean initCloseTopBar() {
        return false;
    }

    @Override
    public CustomUiConfig initCustomUiConfig() {
        CustomUiConfig config = new CustomUiConfig();
        if (isSelf()) {
            config.mTopbarMiddleAreaName=getString(R.string.user_group_about);
        } else {
            config.mTopbarMiddleAreaName=name;
        }
        config.mTopbarLeftAreaName=getString(R.string.back_icon);
        return config;
    }

    private boolean isSelf(){
        if(!LoginInstance.isLogin()){
            return false;
        }
        return uid.equals(LoginInstance.getInstance().getUserInfo().getUid());
    }
}

